import 'package:flutter/material.dart';

class Message extends StatefulWidget {
  @override
  _MessageState createState() => _MessageState();
}
class _MessageState extends State<Message> {

  String val;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: ConstrainedBox(
        constraints: BoxConstraints(
            maxHeight: 40,
            maxWidth: 200
        ),
        child: TextField(

            onSubmitted: (text){
              print(text);
            },
            controller: TextEditingController(
                text: val
            ),
            maxLines: 1,
            decoration: InputDecoration(
              contentPadding: EdgeInsets.symmetric(vertical: 1.0),
                border: OutlineInputBorder(
                    borderRadius: BorderRadius.all(Radius.circular(15)),
                    borderSide: BorderSide(color: Colors.black26, width: 1)),
                hintText: '请输入搜索的内容',
                prefixIcon: Icon(Icons.search),
                suffixIcon: IconButton(
                    icon: Icon(Icons.error_outline),
                    onPressed: () {
                      this.setState((){
                        this.val = "";
                      });
                    })
            ),
          ),
        ),
      appBar: AppBar(
        title: Text('消息'),
      ),
    );
  }
}
